--
-- Author: shunguo.chen
-- Date: 2018-01-09 16:22:42
--
-- CosplaySkillRender cos角色技能

local ClassRef = app.mvc.createRenderClass(...)

function ClassRef.createWithData(data, node)
	local sprite = ClassRef.extend(node or cc.CSLoader:createNode(Res.CosplaySkillNode))
	if node == nil then
		ccui.Helper:doLayout(sprite)
	end
	sprite:init(data)
	return sprite
end     
function ClassRef.create(node)
    return ClassRef.createWithData(nil, node)
end

-- data = Skill
function ClassRef:init(data)
	self.super.init(self, data)
	
	self:setContentSize(self._ui.Panel:getContentSize())

	self._panelSize = self._ui.Panel:getContentSize()
	self._textSize = self._ui.text:getContentSize()

	self:refresh()
end

-- role = CosplayRole
function ClassRef:setRole(role)
	self._role = role
end

function ClassRef:refresh()
	if self._data and self._role then
		local skill = self._data
		self._ui.icon:loadTexture(skill:getIcon())
		self._ui.name:setString(skill:getName())

		local text = self._ui.text
		text:setTextAreaSize(cc.size(self._textSize.width, 0))
		local desc = skill:getDesc(self._role:getAttrs())
		text:setString(desc)

		local size = text:getVirtualRendererSize()
		local dis = size.height - self._textSize.height
		local newSize = self._panelSize
		if dis > 0 then
			newSize = cc.size(self._panelSize.width, self._panelSize.height + dis)
		end
		self._ui.Panel:setContentSize(newSize)
		self:setContentSize(newSize)
		ccui.Helper:doLayout(self._ui.Panel)
	end
end

return ClassRef